package ui.activity.login;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.LinearLayout;

import com.just.agentweb.AgentWeb;
import com.just.agentweb.AgentWebView;

import java.util.HashMap;
import java.util.Map;

import base.BaseBean;
import base.activity.BaseNetActivity;
import bean.ServiceAgreementBean;
import student.andlei.com.student.R;
import utils.GsonUtils;


public class ServiceAgreementActivity extends BaseNetActivity{
    private AgentWeb mAgentWeb;
    private AgentWebView agentWebView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitle("服务协议");

    }

    @Override
    public void success(String action, BaseBean baseBean) {
        if(baseBean.code == 200){
            ServiceAgreementBean agreementBean = (ServiceAgreementBean) GsonUtils.getInstance(context).parseComplexJArrayByCommon(baseBean,ServiceAgreementBean.class);
            mAgentWeb = AgentWeb.with(ServiceAgreementActivity.this)
                    .setAgentWebParent(agentWebView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT))
                    .useDefaultIndicator()
                    .createAgentWeb()
                    .ready()
                    .go(agreementBean.url);
        }else {
            toast(baseBean.msg);
        }
    }

    @Override
    public void error(String action, Throwable e) {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_service_agreement;
    }

    @Override
    protected void findViews() {
        agentWebView = getView(R.id.AgentWebView);
    }

    @Override
    protected void formatViews() {

    }

    @Override
    protected void formatData() {
        loadData();
    }
    private void loadData(){
        //1服务协议 2积分规则 3关于我们
        Map<String,Object> map = new HashMap<>();
        map.put("type",1);
        post("common/article",map,BaseBean.class,false);

        //https://github.com/Justson/AgentWeb    http://www.jd.com
    }
    private WebViewClient mWebViewClient=new WebViewClient(){
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            //do you  work
        }
    };
    private WebChromeClient mWebChromeClient=new WebChromeClient(){
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            //do you work
        }
    };
    @Override
    protected void getBundle(Bundle bundle) {

    }

    @Override
    public void onClick(View v) {

    }
}
